package com.mujin.keji.collectionsystem.module.sign.dapter;

import android.app.Activity;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.listeners.CustomItemClickListener;
import com.mujin.keji.collectionsystem.module.sign.dto.DaysDto;
import com.mujin.keji.collectionsystem.module.sign.views.SignActivity;
import com.mujin.keji.collectionsystem.utils.DateUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


/**
 * 日历
 *
 * @author weishixiong
 * @Time 2018-05-15
 */

public class SignDaydAdapter extends RecyclerView.Adapter<SignDaydAdapter.ViewHolder> {

    private SignActivity mContext;
    private List<DaysDto> datas;
    private SignClikListener listener;

    public interface SignClikListener {
        void onSignClick(DaysDto daysDto);
    }

    public SignDaydAdapter(SignActivity context, List<DaysDto> datas, SignClikListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;


    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_sign_day, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        if (datas.get(position).isSelected()) {
            holder.tvDay.setBackgroundResource(R.drawable.image_selected);
            holder.tvDay.setTextColor(Color.parseColor("#FFFFFF"));
        } else {
            if (datas.get(position).isNowDay()) {
                holder.tvDay.setBackgroundResource(R.drawable.image_now_noselect);
                holder.tvDay.setTextColor(Color.parseColor("#FFFFFF"));
            } else {
                if (datas.get(position).isSign()) {
                    holder.tvDay.setBackgroundResource(R.drawable.image_sign_day);
                    holder.tvDay.setTextColor(Color.parseColor("#FF222222"));
                } else {
                    //判断是不是本月的
                    if (!datas.get(position).isNowMonth()) {
                        holder.tvDay.setTextColor(Color.parseColor("#ffdddddd"));
                    } else {
                        holder.tvDay.setTextColor(Color.parseColor("#FF222222"));
                    }
                }
            }
        }


        holder.tvDay.setText(String.valueOf(datas.get(position).getDay()));
        holder.tvDay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onSignClick(datas.get(position));
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvDay;


        public ViewHolder(View itemView) {
            super(itemView);
            tvDay = (TextView) itemView.findViewById(R.id.tv_day);

        }

    }
}
